z = input("Введите скобочную последовательность: ")
mem = [0, 0, 0, 0, 0, 0, 0, 0]
mem1 = 0
for i in range(len(z)):
    if (z[i] != "(" or z[i] != ")" or z[i] != "{" or z[i] != "}" or z[i] != "<" or z[i] != ">" or z[i] != "[" or z[i] != "]"):
        continue
    if z[i] == "(":
        mem[0] += 1
    elif z[i] == ")":
        mem[1] += 1
    elif z[i] == "[":
        mem[2] += 1
    elif z[i] == "]":
        mem[3] += 1
    elif z[i] == "{":
        mem[4] += 1
    elif z[i] == "}":
        mem[5] += 1
    elif z[i] == "<":
        mem[6] += 1
    else:
        mem[7] += 1
    if (z[i] == ")" and z[i - 1] != "("):
        if (z[i] == ")" and z[i - 1] == "(") and (z[i - 1] == "}" or z[i - 1] == ")" or z[i - 1] == ">" or z[i - 1] == ")"):
            mem1 = 1
            break
        if (z[i - 1] == "(" or z[i - 1] == "{" or z[i - 1] == "<" or z[i - 1] == "["):
            mem1 = 1
            break
    if (z[i] == "}" and z[i - 1] != "{"):
        if (z[i] == "}" and z[i - 1] == "{") and (z[i - 1] == "}" or z[i - 1] == ")" or z[i - 1] == ">" or z[i - 1] == ")"):
            mem1 = 1
            break
        if (z[i - 1] == "(" or z[i - 1] == "{" or z[i - 1] == "<" or z[i - 1] == "["):
            mem1 = 1
            break
    if (z[i] == ">" and z[i - 1] != "<"):
        if (z[i] == ">" and z[i - 1] == "<") and (z[i - 1] == "}" or z[i - 1] == ")" or z[i - 1] == ">" or z[i - 1] == ")"):
            mem1 = 1
            break
        if (z[i - 1] == "(" or z[i - 1] == "{" or z[i - 1] == "<" or z[i - 1] == "["):
            mem1 = 1
            break
    if (z[i] == "]" and z[i - 1] != "["):
        if (z[i] == "]" and z[i - 1] == "[") and (z[i - 1] == "}" or z[i - 1] == ")" or z[i - 1] == ">" or z[i - 1] == ")"):
            mem1 = 1
            break
        if (z[i - 1] == "(" or z[i - 1] == "{" or z[i - 1] == "<" or z[i - 1] == "["):
            mem1 = 1
            break
    if mem[0] < mem[1] or mem[2] < mem[3] or mem[4] < mem[5] or mem[6] < mem[7]:
        mem1 = 1
        break
    if len(z) % 2 != 0:
        mem1 = 1
        break
if mem1 == 0:
    if mem[0] != mem[1] or mem[2] != mem[3] or mem[4] != mem[5] or mem[6] != mem[7]:
        mem1 = 1
if mem1 == 0:
    print(True)
else:
    print(False)
